import Vue from 'vue'
import VueRouter from 'vue-router'
// 页面4大模块
const Home = () => import('@/views/home/Home.vue')
const Source = () => import('@/views/materialCircle/Source.vue')
const Team = () => import('@/views/team/Team.vue')
const Usercenter = () => import('@/views/usercenter/Usercenter.vue')
// 用户权限模块页面
const Login = () => import('@/views/userAdmin/Login.vue')

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/Login', },
  {path: '/Home',name: 'Home',component: Home,},
  {path: '/Source',name: 'Source',component: Source,},
  {path: '/Team',name: 'Team',component: Team,},
  {path: '/Usercenter',name: 'Usercenter',component: Usercenter,},
  { path: '/Login', name: 'Login', component: Login,   },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 首次进入页面权限判断
router.beforeEach((to, from, next) => {
    let token = localStorage.getItem("token")
    if (!token) {
      if (to.path=="/Login"){
        next()
      }else{
        next({ path: '/Login' })
      } 
    } else {
      next()
    }
})

export default router
